package pe.edu.upc.dsd.whereeat.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import pe.edu.upc.dsd.whereeat.base.dao.BaseDAO;
import pe.edu.upc.dsd.whereeat.base.service.impl.BaseServiceImpl;
import pe.edu.upc.dsd.whereeat.dao.LocalDAO;
import pe.edu.upc.dsd.whereeat.dao.RestaurantDAO;
import pe.edu.upc.dsd.whereeat.domain.Local;
import pe.edu.upc.dsd.whereeat.domain.Restaurant;
import pe.edu.upc.dsd.whereeat.service.RestaurantService;

@Service
public class RestaurantServiceImpl extends BaseServiceImpl<Restaurant, Integer>
		implements RestaurantService {

	@Autowired
	private RestaurantDAO restaurantDAO;

	@Autowired
	private LocalDAO localDAO;

	public RestaurantServiceImpl() {
	}

	@Override
	protected BaseDAO<Restaurant, Integer> getBaseDAO() {
		return restaurantDAO;
	}

	@Transactional
	public void saveRestaurant(Restaurant restaurant) throws Exception {
		restaurantDAO.save(restaurant);
		for (Local local : restaurant.getLocals()) {
			localDAO.save(local);
		}
	}

}
